package mao.thinkinjava.concurency.myenum;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;

/**
 * clazz.getGenericInterface()返回参数化类型，实际没有用。
 */
enum Explore{HERE,THERE}
public class Reflection {
    public static Set<String> getMethods(Class<? extends Enum> clazz){
        System.out.println("explore"+clazz.getSimpleName()+"=======");
        System.out.println("interface");
        Type[] interfaces = clazz.getGenericInterfaces();

        for (int i = 0; i < interfaces.length; i++) {
            System.out.println(interfaces[i]);
        }
        System.out.println("base"+clazz.getGenericSuperclass());
        System.out.println("method");
        Method[] methods = clazz.getMethods();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < methods.length; i++) {
            set.add(methods[i].getName());
        }
        System.out.println(set);
        return set;
    }

    public static void main(String[] args) {
        Set<String> exploreM = getMethods(Explore.class);
        Set<String> enumM = getMethods(Enum.class);
        System.out.println(exploreM.contains(enumM));
        exploreM.removeAll(enumM);
        System.out.println(exploreM);

       //Enum向上转型。
        Enum en = Explore.HERE;
        for(Enum e : en.getClass().getEnumConstants() ){
            System.out.println(e.name());
        }
    }
}
